package com.wangyi.im.config;

import com.wangyi.im.remoting.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@RefreshScope
@Configuration
@EnableConfigurationProperties(IMConfig.class)
@ConfigurationProperties(prefix = "wangyi.im")
public class IMConfig {

    /**
     * appKey
     **/
    private String appKey;

    /**
     * 秘钥
     **/
    private String appSecret;

    /**
     * 推送服务器地址
     **/
    private String url;

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Bean
    public IMTokenRemoting imTokenRemoting() {
        return new IMTokenRemoting(url, appKey, appSecret);
    }

    @Bean
    public IMUserRemoting imUserRemoting() {
        return new IMUserRemoting(url, appKey, appSecret);
    }

    @Bean
    public IMMessageRemoting imMessageRemoting() {
        return new IMMessageRemoting(url, appKey, appSecret);
    }

    @Bean
    public IMFriendRemoting imFriendRemoting() {
        return new IMFriendRemoting(url, appKey, appSecret);
    }

    @Bean
    public IMEventSubscribeRemoting imEventSubscribeRemoting() {
        return new IMEventSubscribeRemoting(url, appKey, appSecret);
    }


    /**
     * 此配置可将http的headers设置成可使用通配符匹配参数
     * */
    /*@Configuration
    public class RequestMappingHandlerMappingRegister implements WebMvcRegistrations{
        @Override
        public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
            return new ExtRequestMappingHandlerMapping();
        }
    }*/
}
